﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NLog;
namespace MT4Trainer
{
    using Encog.Plugin;
    using Encog.Util.Logging;

    class NLogEncogLogger : IEncogPluginLogging1
    {

        public NLog.Logger mLogger = NLog.LogManager.GetCurrentClassLogger();


        NLogEncogLogger()
        {
            NLog.LogManager.ReconfigExistingLoggers();
            mLogger = NLog.LogManager.GetCurrentClassLogger();
        }

        public NLogEncogLogger(NLog.Logger logger)
        {
            this.mLogger = logger;
        }
        #region Implementation of EncogPluginBase


        #endregion

        #region Implementation of EncogPluginBase

        /// <value>The type number for this plugin.</value>
        public EncogPluginType PluginType
        {
            get
            {
                return EncogPluginType.Logging;
            }
        }

        /// <value>The service type provided by this plugin.</value>
        public ServiceType PluginServiceType
        {
            get
            {
                return ServiceType.LOGGING;
            }
        }

        /// <value>The name of the plugin.</value>
        public string PluginName
        {
            get
            {
                return "NLog For Encog";
            }
        }

        /// <value>The plugin description.</value>
        public string PluginDescription
        {
            get
            {
                return "Logs all encog logs to nlog logger";
            }
        }

        #endregion

        #region Implementation of IEncogPluginLogging1

        /// <summary>
        /// The current log level.
        /// </summary>
        public EncogLogging.LogLevel LogLevel
        {
            get
            {
                return EncogLogging.LogLevel.Trace;
            }
        }

        /// <summary>
        /// Log a message at the specified level. 
        /// </summary>
        /// <param name="level">The level to log at.</param>
        /// <param name="message">The message to log.</param>
        public void Log(EncogLogging.LogLevel level, string message)
        {
            switch (level)
            {
                case EncogLogging.LogLevel.None:

                    break;
                case EncogLogging.LogLevel.Trace:
                    mLogger.Trace(() => message);
                    break;
                case EncogLogging.LogLevel.Debug:
                    mLogger.Debug(() => message);
                    break;
                case EncogLogging.LogLevel.Info:
                    mLogger.Info(() => message);
                    break;
                case EncogLogging.LogLevel.Warn:
                    mLogger.Warn(() => message);
                    break;
                case EncogLogging.LogLevel.Error:
                    mLogger.Error(() => message);
                    break;
                case EncogLogging.LogLevel.Critical:
                    mLogger.Error(message);
                    break;
            }
        }

        /// <summary>
        ///  Logs a trace trace message
        /// </summary>
        /// <param name="message"> The message to log. </param>
        public void LogTrace(string message)
        {
            mLogger.Trace(()=>message);
        }

        /// <summary>
        ///  Logs a debug message
        /// </summary>
        /// <param name="message"> The message to log. </param>
        public void LogDebug(string message)
        {
           mLogger.Debug(()=>message);
        }

        /// Log a message at the info level.
        /// </summary>
        /// <param name="message">The message to log.</param>
        public void Log(string message)
        {
            mLogger.Info(message);
        }

        /// <summary>
        /// Log a throwable at the specified level.
        /// </summary>
        /// <param name="level">The level to log at.</param>
        /// <param name="t">The error to log.</param>
        public void Log(EncogLogging.LogLevel level, Exception t)
        {
            mLogger.LogException(NLog.LogLevel.Error, t.Message, t);
        }

        #endregion
    }
}
